from PySide6.QtCore import Signal, QThread


class ThreadWorker_Signal(QThread):
    log_signal = Signal(str, int)  # 输出Log信号
    to_end_signal = Signal()  # 滚动条滚动到底部信号
    start_signal = Signal()  # 任务开始执行信号
    end_signal = Signal()  # 任务执行完毕信号
    add_list_signal = Signal()  # 添加列表数据信号

    def __init__(self, fn, *args, **kwargs):
        super().__init__()
        self.fn = fn
        self.args = args
        self.kwargs = kwargs
        self.kwargs["log_signal"] = self.log_signal
        self.kwargs["to_end_signal"] = self.to_end_signal
        self.kwargs["start_signal"] = self.start_signal
        self.kwargs["end_signal"] = self.end_signal
        self.kwargs["add_list_signal"] = self.add_list_signal

    def run(self):
        self.fn(*self.args, **self.kwargs)


class ThreadWorker_Simple(QThread):
    def __init__(self, fn, *args, **kwargs):
        super().__init__()
        self.fn = fn
        self.args = args
        self.kwargs = kwargs

    def run(self):
        self.fn(*self.args, **self.kwargs)
